package com.chen.spring.cloud.miniapp.api.feign.controller;

import com.chen.entity.User;
import com.chen.spring.cloud.miniapp.api.feign.service.CouponService;
import com.chen.spring.cloud.miniapp.api.feign.service.UserService;
import com.chen.util.MapperUtils;
import com.chen.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/Coupon")
public class CouponController {

    @Autowired
    private UserService userService;

    @Autowired
    private CouponService couponService;

    public R myList(String wx_openid,String limit){

        String userjson = userService.getUidByOpenid(wx_openid);
        try {
            User user = MapperUtils.json2pojo(userjson, User.class);
            String result = couponService.myList(user.getU_id(),limit);
            Map<String,Object> map = MapperUtils.json2map(result);
            return R.ok(map);
        } catch (Exception e){
            e.printStackTrace();
        }

        return R.error(400,"没有更多的优惠券了！");
    }

}
